<?php
class TwitterComponent extends Object {

	public $components = array('OauthConsumer');
	public $format = 'json';
	private $token = array(
	    'key' => '19258729-FUnEaaGfqx3KrPRZzue6UgW6rzuNrJB7piuAQFqww',
	    'secret' => 'EyWbQnSfbElYrgFxjbVdSn5M3st6JWyVE4UdxHgzTM'		
	);

# directMessages	
# options:
#	since_id -- Returns only direct messages with an ID greater than (that is, more recent than) the specified ID
# 	page -- Retrieves the 20 next most recent direct messages.
# returns: http://apiwiki.twitter.com/REST+API+Documentation#Directmessageelement
	public function directMessages($options = false) {
		if (!$options) $options = array();
		$url = 'http://twitter.com/direct_messages.' . $this->format;
		return $this->_send($url, $options);
	} // directMessages
	
# friendsTimeline
# options: 
# 	since_id -- Returns only statuses with an ID greater than (that is, more recent than) the specified ID
# 	max_id -- Returns only statuses with an ID less than (that is, older than) the specified ID
#	count -- Specifies the number of statuses to retrieve. May not be greater than 200
# 	page -- 
# returns: http://apiwiki.twitter.com/REST+API+Documentation#Statuselement
	public function friendsTimeline($options = false) {
		if (!$options) $options = array();		
		$url = 'http://twitter.com/statuses/friends_timeline.' . $this->format;
		return $this->_send($url, $options);		
	} // friendsTimeline
	
# userTimeline
# options:
# 	id -- Specifies the ID or screen name of the user for whom to return the user_timeline. 
# 	user_id -- Specfies the ID of the user for whom to return the user_timeline. Helpful for disambiguating when a valid user ID is also a valid screen name.
# 	screen_name -- Specfies the screen name of the user for whom to return the user_timeline.
# 	since_id -- Returns only statuses with an ID greater than (that is, more recent than) the specified ID. 
# 	max_id	-- Returns only statuses with an ID less than (that is, older than) the specified ID. 
# 	page -- 
# returns: http://apiwiki.twitter.com/REST+API+Documentation#Statuselement
	public function userTimeline($options = false) {
		if (!$options) $options = array();		
		$url = 'https://twitter.com/statuses/user_timeline.' . $this->format;
		return $this->_send($url, $options);	
	} // userTimeline

# _send
# send a request to twitter	
	private function _send($url, $options, $method = 'get') {
		if($method == 'get') :
        	$data = $this->OauthConsumer->get('Twitter', $this->token['key'], $this->token['secret'], $url, $options);		
		elseif($method == 'post') :
			$data = $this->OauthConsumer->post('Twitter', $this->token['key'], $this->token['secret'], $url, $options);		
		endif; 
		
		return json_decode($data);		
	}
	
} // TwitterComponent	
?>